package com.demozz.circle_ratio_fraction;

/**
 * 圆周率连分数
 *
 */
public class App {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        int ap = 0;
        int a = 1;
        int bp = 1;
        int b = 0;
        int aa = 0;
        int bb = 0;
        int y = 0;
        double yyp = 0.0;
        for (int i = 0; i < 12; i++) {
            aa = ap + (-bp * y);
            bb = a + (-b * y);
            System.out.println("aa=" + aa);
            System.out.println("bb=>" + bb);
            System.out.println(".....aa=" + ap + "+" + "(-" + bp + "*" + y + ")");
            System.out.println(".....bb=>" + a + "+" + "(-" + b + "*" + y + ")");
            ap = bp;
            a = b;
            bp = aa;
            b = bb;
            yyp = uu(ap, a, bp, b);
            System.out.println("y=" + yyp);
            y = (int) yyp;
        }
        System.out.println("pppp=>" + (80143857.0 / 25510582)); // pppp=>3.1415926535897927
        System.out.println("pppp=>" + (165707065.0 / 52746197));// pppp=>3.1415926535897936 11
        System.out.println("pppp=>" + (80143857.0 / 25510582)); // pppp=>3.1415926535897927
    }

    private static double uu(int ap, int a, int bp, int b) {
        double z = (ap * Math.PI + a) / (bp * Math.PI + b);// 0 1 1 -3
        return z;
    }
}
